<?php
/**
 * User: papa
 * Date: 18/5/10
 * Time: 11:43
 */

namespace app\admin\model;


class User extends BaseModel
{
    //获取器，用户性别gender
    public function getGenderAttr($value)
    {
        $status = [0=>'未知',1=>'男性',2=>'女性'];
        return $status[$value];
    }

    //指定条件查询及分页样式
    public static function getAllUser($num,$data = null)
    {
            if (!empty($data['tel']))  $where['tel'] = ['like','%'.$data['tel'].'%'];
            if (!empty($data['nickname']))  $where['nickname'] = ['like','%'.$data['nickname'].'%'];
            if(!isset($where))  $where = null;
            if (!empty($data['start_time']) && !empty($data['end_time'])) {
                $result = self::where($where)
                    ->order('create_time', 'desc')
                    ->whereTime('create_time', 'between', [$data['start_time'], $data['end_time']])
                    ->paginate($num, false, [
                        'type' => 'page\Page',
                    ]);
             }else{
                $result = self::where($where)->order('create_time', 'desc')
                    ->paginate($num, false, [
                        'type' => 'page\Page',
                    ]);
            }
            return $result;
    }
}